package com.lxhll.personnel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxhll.personnel.dao.ProbationDao;
import com.lxhll.personnel.entity.Probation;
import com.lxhll.personnel.service.ProbationService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;


/**
 * (Position)表服务实现类
 *
 * @author makejava
 * @since 2021-07-18 01:06:38
 */
@Service
public class ProbationServiceImpl extends ServiceImpl<ProbationDao,Probation> implements ProbationService {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;
    @Override
    public Probation getProbationByEmployeeId(Integer id) {

        Object probation=redisTemplate.opsForValue().get("probation_employee_"+id);
        if (probation == null) {
            probation = this.baseMapper.selectOne(new QueryWrapper<Probation>().eq("employee_id",id));
            redisTemplate.opsForValue().set("probation_employee_" + id, probation, 1, TimeUnit.HOURS);
        }
        return (Probation) probation;
    }

    @Override
    public Probation updateProbationById(Probation probation) {
        this.updateById(probation);
        redisTemplate.opsForValue().set("probation_employee_" + probation.getEmployeeId(), probation, 1, TimeUnit.HOURS);
        return probation;
    }
}
